#include "MLSDialog.h"
#include "ui_MLSDialog.h"

MLSDialog::MLSDialog(QWidget *parent)
	: QDialog(parent)
	, Ui::MLSDialog()
{
	setupUi(this);
	updateCombo();
	connect (this->comboBox_upsamplingMethod, SIGNAL(currentIndexChanged(QString)), this, SLOT(activateMenu(QString)));
	connect (this->doubleSpinBox_searchRadius, SIGNAL(valueChanged(double)), this, SLOT(updateSquaredGaussian(double)) );
	deactivateAllMethods();
}

void MLSDialog::updateCombo()
{
	this->comboBox_upsamplingMethod->clear();
	this->comboBox_upsamplingMethod->addItem(QString("None"));
	this->comboBox_upsamplingMethod->addItem(QString("Sample Local Plane"));
	this->comboBox_upsamplingMethod->addItem(QString("Random Uniform Density"));
	this->comboBox_upsamplingMethod->addItem(QString("Voxel Grid Dilation"));
}

void MLSDialog::activateMenu(QString name)
{
	deactivateAllMethods();

	if (name == "Sample Local Plane")
	{
		this->groupBox->setEnabled(true);
	}
	else if (name == "Random Uniform Density")
	{
		this->groupBox_2->setEnabled(true);
	}
	else if (name == "Voxel Grid Dilation")
	{
		this->groupBox_3->setEnabled(true);
	}
	else
	{
		deactivateAllMethods();
	}
}

void MLSDialog::deactivateAllMethods()
{
	this->groupBox->setEnabled(false);
	this->groupBox_2->setEnabled(false);
	this->groupBox_3->setEnabled(false);
}

void MLSDialog::toggleMethods(bool status)
{
	if (!status)
		deactivateAllMethods();
}

void MLSDialog::updateSquaredGaussian(double radius)
{
	this->doubleSpinBox_sqrGauss->setValue(radius * radius);
}
